package com.iuie.ns.system.controller.setting;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.iuie.ns.frame.web.response.vo.ResponseInfo;
import com.iuie.ns.system.service.setting.ISysUserSettingService;
import com.iuie.ns.system.vo.setting.ListUserSettingForm;
import com.iuie.ns.system.vo.setting.SysUserSettingVO;

/**
 * 用户设置-controller
 * @author liujie
 * @date 2018年3月17日下午4:51:52
 */
@Controller
@RequestMapping("setting")
public class SysUserSettingController {
	
	@Resource
	private ISysUserSettingService userSettingService;
	

	/**
	 * 用户设置页面
	 * @param userId
	 * @return
	 * @date 2018年3月17日下午4:50:32
	 */
	@RequestMapping("index")
	public String userSettingIndex(HttpServletRequest request) {
		return "view-system/setting/userSetting";
	}
	
	/**
	 * 保存所有用户设置信息
	 * @param list
	 * @return
	 * @date 2018年3月26日下午9:38:23
	 */
	@RequestMapping(value = "save/all", method = RequestMethod.POST)
	@ResponseBody
	public ResponseInfo saveAll(@RequestBody ListUserSettingForm list) {
		userSettingService.saveAll(list.getUserSettings());
		return ResponseInfo.successInfo("保存成功！");
	}
	
	/**
	 * 查询当前用户的所有设置信息
	 * @return
	 * @date 2018年4月1日上午11:22:56
	 */
	@RequestMapping(value = "find/all", method = RequestMethod.GET)
	@ResponseBody
	public ResponseInfo findAll() {
		List<SysUserSettingVO> list = userSettingService.findAll();
		return ResponseInfo.successInfoByObject(list);
	}
	
	/**
	 * 查询当前用户当前角色的settingKey对应的用户设置
	 * @param settingKey
	 * @return
	 * @date 2018年4月1日下午1:14:55
	 */
	@RequestMapping(value = "find/setting/{settingKey}", method = RequestMethod.GET)
	@ResponseBody
	public ResponseInfo findOneBySettingKey(@PathVariable("settingKey") String settingKey) {
		SysUserSettingVO item = userSettingService.findOneBySettingKey(settingKey);
		return ResponseInfo.successInfoByObject(item);
	}
	
	/**
	 * 查询当前用户当前角色的settingKeys
	 * @return List&lt;String&gt;
	 * @date 2018年3月31日下午6:04:26
	 */
	@RequestMapping(value = "find/current/settingKeys", method = RequestMethod.GET)
	@ResponseBody
	public ResponseInfo findCurrentRoleSettingKeys() {
		List<String> list = userSettingService.findCurrentRoleSettingKeys();
		return ResponseInfo.successInfo(list);
	}
	
}
